//
//  LYNewFeatureCell.m
//  lottery
//
//  Created by 赵国腾的MacBook Pro on 16/6/26.
//  Copyright © 2016年 赵国腾. All rights reserved.
//

#import "LYNewFeatureCell.h"
#import "LYTabBarController.h"

@interface LYNewFeatureCell ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIButton *startButton;

@end

@implementation LYNewFeatureCell

- (UIImageView *)imageView {
    
    if (_imageView == nil) {
        
        _imageView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
        [self.contentView addSubview:_imageView];
    }
    
    return _imageView;
}

- (UIButton *)startButton {
    
    if (_startButton == nil) {
        
        // 如果使用类方法的时候，苹果帮我们管理内存
        _startButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_startButton setBackgroundImage:[UIImage imageNamed:@"guideStart"] forState:UIControlStateNormal];
        [_startButton sizeToFit];
        _startButton.gt_midX = self.contentView.gt_midX;
        _startButton.gt_maxY = self.contentView.gt_maxY - 30;
        [_startButton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_startButton];
    }
    
    return _startButton;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setImage:(UIImage *)image {
    
    _image = image;
    
    self.imageView.image = image;
}

- (void)setupIndexPath:(NSIndexPath *)indexPath count:(NSInteger)pagesCount {
    
    self.startButton.hidden = YES;
    if (indexPath.row == pagesCount - 1) {
        
        self.startButton.hidden = NO;
    }
}

// 立即体验
- (void)start {
    
    LYKeyWindow.rootViewController = [[LYTabBarController alloc] init];
    
    CATransition *anim = [CATransition animation];
    
    anim.duration = 0.5;
    anim.type = @"reveal";
    
    [LYKeyWindow.layer addAnimation:anim forKey:nil];
}

@end
